require 'cgi'
module SemanticText
  
  class Verbatim
    attr_reader :lines

    @end_of_section_block = {}

    def initialize(&end_of_section_handler)
      @lines= []
      @end_of_section_block = end_of_section_handler
    end

    #Parse line of text into a verbatim block. 
    #Runs end of verbatim handler when end of verbatim found.
    def parse(line)
      if line=='}}}'
        @end_of_section_block.call
      else
        @lines << line
      end
    end

    def export_html
      out = "\n<pre>\n"
      lines.each  {|line | out += CGI.escapeHTML(line)+"\n" }
      out += "</pre>\n"
    end

  end
end
